package jp.sinmetal.trainer.action;

import java.sql.Timestamp;


import javax.annotation.Resource;

import org.apache.struts.action.ActionMessages;
import org.seasar.framework.beans.util.Beans;
import org.seasar.struts.annotation.ActionForm;
import org.seasar.struts.annotation.Execute;
import java.util.List;

import org.seasar.extension.jdbc.JdbcManager;
import org.seasar.extension.jdbc.where.SimpleWhere;

import jp.sinmetal.trainer.entity.Battle;
import jp.sinmetal.trainer.form.BattleForm;
import jp.sinmetal.trainer.service.BattleService;

public class BattleAction {


    public List<Battle> battleItems;
    
    @ActionForm
    @Resource
    protected BattleForm battleForm;

    @Resource
    protected BattleService battleService;

    public JdbcManager jdbcManager;

    @Execute(validator = false)
    public String index() {
        battleItems = battleService.findAll();

        return "list.jsp";
    }





    @Execute(validator = false, urlPattern = "show/{battleId}")
    public String show() {
        Battle entity = battleService.findById(Integer.valueOf(battleForm.battleId));
        Beans.copy(entity, battleForm).dateConverter("yyyy-MM-dd").execute();
        return "show.jsp";
    }

    @Execute(validator = false, urlPattern = "edit/{battleId}")
    public String edit() {
        Battle entity = battleService.findById(Integer.valueOf(battleForm.battleId));
        Beans.copy(entity, battleForm).dateConverter("yyyy-MM-dd").execute();
        return "edit.jsp";
    }

    @Execute(validator = false)
    public String create() {
        return "create.jsp";
    }

    @Execute(validator = false, urlPattern = "delete/{battleId}/{version}", redirect = true)
    public String delete() {
        Battle entity = Beans.createAndCopy(Battle.class, battleForm).dateConverter("yyyy-MM-dd").execute();
        battleService.delete(entity);
        return "/battle/";
    }

    @Execute(input = "create.jsp", redirect = true)
    public String insert() {
        Battle entity = Beans.createAndCopy(Battle.class, battleForm).dateConverter("yyyy-MM-dd").execute();
        battleService.insert(entity);
        return "/battle/";
    }

    @Execute(input = "edit.jsp", redirect = true)
    public String update() {
        Battle entity = Beans.createAndCopy(Battle.class, battleForm).dateConverter("yyyy-MM-dd").execute();
        battleService.update(entity);
        return "/battle/";
    }
}